public class a {
    public static int[] qsort(int arr[], int start, int end) {
        if (start >= end) return arr;

        int pivot = arr[start];
        int i = start - 1;
        int j = end + 1;

        while (i < j) {
            do { j--; } while (arr[j] > pivot);
            do { i++; } while (arr[i] < pivot);

            if (i < j) {
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        qsort(arr, start, j);
        qsort(arr, j + 1, end);
        return arr;
    }
    public static void main1(String[] args) {
        int[] arr=new int[]{45,12,45,11,78,66,14,11,2,43};
        int[] arr1=qsort(arr,0,9);
        for(int a:arr1){
            System.out.printf("%d ",a);
        }
    }
    public static int[] csort(int arr[],int n){
        if(arr==null||arr.length==0){
            return new int[0];
        }
        int max=arr[0];
        for(int i=1;i<n;i++){
            max=Math.max(max,arr[i]);
        }
        int[] temp=new int[max+1];
        for(int i=0;i<n;i++){
            temp[arr[i]]++;
        }
        for(int i=1;i<temp.length;i++){
            temp[i]+=temp[i-1];
        }
        int[] sort=new int[arr.length];
        for(int i=arr.length-1;i>=0;i--){
            sort[--temp[arr[i]]]=arr[i];
        }
        return (sort);
    }
    public static void main(String[] args) {
        int[] arr=new int[]{1,2,2,5,5,4,1,0,3,4};
        int[] arr1=csort(arr,arr.length);
        for(int a:arr1){
          System.out.printf("%d ",a);
       }

    }
}
